import moment from 'moment'

export function getformDatas(data: any) {
	const {
		socialCreditCode,
		abbreviation,
		supplierName,
		supplierCode,
		supplierCreator,
		ratingCycle,
	} = data

	const {
		enterpriseNature,
		address,
		payCondition,
		invoicingRate,
		telephone,
		contacts,
		mobilePhone,
		email,
		registeredCapital,
		establishDate,
		postalCode,
		companyIntroduction,
		accountBankName,
		accountName,
		bankAccount,
		bankName,
		support,
		provinceId,
		cityId,
		settlementMethod,
		earnestMoney,
	} = data?.supplierBase || {}

	const admittanceValue = {
		supplierType: data.supplierType.split(','),
		socialCreditCode,
		supplierName,
		abbreviation,
		supplierCode,
		supplierCreator,
		examineOrgId: data?.supplierBase?.examineOrgId,
		orgId: data?.orgId?.split(','),
		ratingCycle,
		reason: data?.supplierBase?.reason,
	}

	const basicsValue = {
		enterpriseNature,
		address,
		payCondition,
		invoicingRate,
		telephone,
		contacts,
		mobilePhone,
		email,
		registeredCapital,
		establishDate: establishDate ? moment(establishDate) : '',
		postalCode,
		companyIntroduction,
		city: cityId ? [provinceId, cityId] : [],
		settlementMethod,
		earnestMoney,
	}

	const bankValue = {
		support,
		bankName,
		accountName,
		bankAccount,
		accountBankName,
	}

	return {
		admittanceValue,
		basicsValue,
		bankValue,
	}
}
export function getUrls(urlDatas: any, type: string) {
	let urls = []
	if (type === 'DYY_GYS') {
		urls = [
			urlDatas?.businessLicenseUrl,
			urlDatas?.historicalRegistrationUrl,
			urlDatas?.businessInspectionUrl,
			urlDatas?.officeContractUrl,
			urlDatas?.shareholderConditionUrl,
			urlDatas?.scopeQualificationUrl,
			urlDatas?.customerContractUrl,
			urlDatas?.supplierContract,
			urlDatas?.serviceInspectionUrl,
			urlDatas?.organizationStructureUrl,
			urlDatas?.insuranceCertificateUrl,
			urlDatas?.socialPayCertificateUrl,
			urlDatas?.recentReportsUrl,
			urlDatas?.taxDeclarationUrl,
			urlDatas?.companyArbitrationUrl,
			urlDatas?.administrativePenaltyUrl,
			urlDatas?.supportingCollateralUrl,
			urlDatas?.otherDocumentsUrl1,
			urlDatas?.otherDocumentsUrl2,
			urlDatas?.otherDocumentsUrl3,
			urlDatas?.otherFileUrl1,
			urlDatas?.otherFileUrl2,
			urlDatas?.otherFileUrl3,
			urlDatas?.serviceOtherDocumentUrl1,
			urlDatas?.serviceOtherDocumentUrl2,
			urlDatas?.serviceOtherDocumentUrl3,
		]?.map(Number)
	} else {
		const arr = [
			urlDatas?.businessLicenseUrl,
			urlDatas?.openingPermitUrl,
			urlDatas?.confidentialityCommitmentUrl,
			urlDatas?.corporateCardUrl,
			urlDatas?.creditReportUrl,
			urlDatas?.registrationFormUrl,
			urlDatas?.statementIntegrityUrl,
			urlDatas?.moralityStandardUrl,
			urlDatas?.moralityStandardPromiseUrl,
			urlDatas?.certificationPhotosUrl,
			urlDatas?.contractScanningUrl,
			urlDatas?.depositLetterUrl,
			urlDatas?.otherDocumentsUrl1,
			urlDatas?.otherDocumentsUrl2,
			urlDatas?.otherDocumentsUrl3,
		]?.map(Number)
		if (type === 'SP_GYS') {
			urls = arr.concat(urlDatas?.contractFileUrl?.split(','))
		} else {
			urls = arr
		}
	}

	return urls
}
/** 组合所有上传字段 */
export function getUrlData(urlDatas: any, type: string) {
	let newUrlData: any = {}
	if (type === 'DYY_GYS') {
		newUrlData = {
			businessLicenseUrl: urlDatas?.businessLicenseUrl,
			historicalRegistrationUrl: urlDatas?.historicalRegistrationUrl,
			businessInspectionUrl: urlDatas?.businessInspectionUrl,
			officeContractUrl: urlDatas?.officeContractUrl,
			shareholderConditionUrl: urlDatas?.shareholderConditionUrl,
			scopeQualificationUrl: urlDatas?.scopeQualificationUrl,
			customerContractUrl: urlDatas?.customerContractUrl,
			supplierContract: urlDatas?.supplierContract,
			serviceInspectionUrl: urlDatas?.serviceInspectionUrl,
			organizationStructureUrl: urlDatas?.organizationStructureUrl,
			insuranceCertificateUrl: urlDatas?.insuranceCertificateUrl,
			socialPayCertificateUrl: urlDatas?.socialPayCertificateUrl,
			recentReportsUrl: urlDatas?.recentReportsUrl,
			taxDeclarationUrl: urlDatas?.taxDeclarationUrl,
			companyArbitrationUrl: urlDatas?.companyArbitrationUrl,
			administrativePenaltyUrl: urlDatas?.administrativePenaltyUrl,
			supportingCollateralUrl: urlDatas?.supportingCollateralUrl,
			otherDocumentsUrl1: urlDatas?.otherDocumentsUrl1,
			otherDocumentsUrl2: urlDatas?.otherDocumentsUrl2,
			otherDocumentsUrl3: urlDatas?.otherDocumentsUrl3,
			otherFileUrl1: urlDatas?.otherFileUrl1,
			otherFileUrl2: urlDatas?.otherFileUrl2,
			otherFileUrl3: urlDatas?.otherFileUrl3,
			serviceOtherDocumentUrl1: urlDatas?.serviceOtherDocumentUrl1,
			serviceOtherDocumentUrl2: urlDatas?.serviceOtherDocumentUrl2,
			serviceOtherDocumentUrl3: urlDatas?.serviceOtherDocumentUrl3,
		}
	} else {
		newUrlData = {
			businessLicenseUrl: urlDatas?.businessLicenseUrl,
			openingPermitUrl: urlDatas?.openingPermitUrl,
			confidentialityCommitmentUrl:
				urlDatas?.confidentialityCommitmentUrl,
			corporateCardUrl: urlDatas?.corporateCardUrl,
			creditReportUrl: urlDatas?.creditReportUrl,
			registrationFormUrl: urlDatas?.registrationFormUrl,
			statementIntegrityUrl: urlDatas?.statementIntegrityUrl,
			moralityStandardUrl: urlDatas?.moralityStandardUrl,
			moralityStandardPromiseUrl: urlDatas?.moralityStandardPromiseUrl,
			certificationPhotosUrl: urlDatas?.certificationPhotosUrl,
			contractScanningUrl: urlDatas?.contractScanningUrl,
			depositLetterUrl: urlDatas?.depositLetterUrl,
			otherDocumentsUrl1: urlDatas?.otherDocumentsUrl1,
			otherDocumentsUrl2: urlDatas?.otherDocumentsUrl2,
			otherDocumentsUrl3: urlDatas?.otherDocumentsUrl3,
		}
	}

	return newUrlData
}
